/** *******************************************************************
 
 * Copyright (c) 2008 Jonnie Spratley. All Rights Reserved.
 * @author  Jonnie Spratley
 * @contact jonniespratley@gmail.com
 * @internal
 ******************************************************************* */
package com.jonniespratley.codegen.vo
{ 
	[Bindable]
	public class Table extends Object
	{
		public var name:String;
		public var key:String;
		public var fields:Array;
		
		public function  Table( obj:Object = null )
		{
			if ( obj != null )
			{
				this.name = obj['label'];
				
				this.key =  obj['aKey'];
				
				/* ***********************************************
				 * Field parsing
				 *********************************************** */
				var tempFieldArray:Array = obj['children'] as Array;
				var tempFieldAC:Array = new Array();

				for ( var fString:String in tempFieldArray )
				{
					tempFieldAC.push( new Field( tempFieldArray[ fString ] ) );	
				}
				this.fields = tempFieldAC;
			}
		}
 
		public function get alias():String {
			return this.name.replace( this.name.charAt(0), this.name.charAt(0).toUpperCase() );
		}
		public function get children():Array{
			return this.fields;
		}
		public function get label():String{
			return this.name;
		}
  
	}
}